/* === H E A D E R S ======================================================= */

#ifdef USING_PCH
#	include "pch.h"
#else
#ifdef HAVE_CONFIG_H
#	include <config.h>
#endif

#include <vector>

#include <gtk/gtk.h>

#include <gtkmm/aboutdialog.h>

#include <ETL/stringf>

#include <synfig/general.h>

// This is generated at make time from .svn or .git/svn or autorevision.conf
#include <autorevision.h>

#include "about.h"
#include "app.h"

#include "general.h"

#endif

/* === U S I N G =========================================================== */

using namespace std;
using namespace etl;
using namespace studio;

/* === M A C R O S ========================================================= */

#ifndef VERSION
#define VERSION	"unknown"
#define PACKAGE	"synfigstudio"
#endif

#ifdef WIN32
#	ifdef IMAGE_DIR
#		undef IMAGE_DIR
#		define IMAGE_DIR "share\\pixmaps"
#	endif
#endif

#ifndef IMAGE_DIR
#	define IMAGE_DIR "/usr/local/share/pixmaps"
#endif

#ifndef IMAGE_EXT
#	define IMAGE_EXT	"png"
#endif

#define stringify_(x) #x
#define stringify(x) stringify_(x)

/* === G L O B A L S ======================================================= */

extern const guint gtk_major_version;
extern const guint gtk_minor_version;
extern const guint gtk_micro_version;
extern const guint gtk_binary_age;
extern const guint gtk_interface_age;

/* === P R O C E D U R E S ================================================= */

/* === M E T H O D S ======================================================= */

About::About()
{

#ifdef HAVE_GTK_ABOUTDIALOG_SET_PROGRAM_NAME
	set_program_name("ArtIA Studio");
#else
	set_name("ArtIA Studio");
#endif
	set_version("0.9.95.0031");
	set_comments(_("2D vector animation studio"));

	set_url_hook(sigc::mem_fun(*this, &About::on_link_clicked));
	set_website("http://www.janastech.com/");
	set_website_label(_("Sito web di Janas Technology"));

	set_copyright(_("Copyright 2006-2008\nJanas Technology S.r.l."));
	Glib::ustring license =
		"This program is free software; you can redistribute it and/or modify "
		"it under the terms of the GNU General Public License as published by "
		"the Free Software Foundation; either version 2 of the License, or "
		"(at your option) any later version.\n\n"

		"This program is distributed in the hope that it will be useful, "
		"but WITHOUT ANY WARRANTY; without even the implied warranty of "
		"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the "
		"GNU General Public License for more details.\n\n"

		"You should have received a copy of the GNU General Public License along "
		"with this program; if not, write to the Free Software Foundation, Inc., "
		"51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or visit: http://www.gnu.org/";
	set_license(license);
#ifdef HAVE_GTK_ABOUTDIALOG_SET_WRAP_LICENSE
	set_wrap_license(true);
#endif

	std::vector<Glib::ustring> authors;

	authors.push_back("Sviluppo:");
	authors.push_back("TD Group S.p.A.");
	authors.push_back("");
	authors.push_back("Management:");
	authors.push_back("Maria Teresa Musci (Janas Technology S.r.l.)");	
	authors.push_back("Marco Benvenuti (TD Group S.p.A)");
	

	set_authors(authors);

	std::vector<Glib::ustring> artists;
	artists.push_back("Federica Latteri");
	artists.push_back("Elena Zarelli");
	artists.push_back("Eva Peirano");

	set_artists(artists);

	std::string imagepath;
#ifdef WIN32
	imagepath=App::get_base_path()+ETL_DIRECTORY_SEPARATOR+IMAGE_DIR;
#else
	imagepath=IMAGE_DIR;
#endif
	char* synfig_root=getenv("SYNFIG_ROOT");
	if(synfig_root) {
		imagepath=synfig_root;
		imagepath+=ETL_DIRECTORY_SEPARATOR;
		imagepath+="share";
		imagepath+=ETL_DIRECTORY_SEPARATOR;
		imagepath+="pixmaps";
	}
	imagepath+=ETL_DIRECTORY_SEPARATOR;

	Gtk::Image *Logo = manage(new class Gtk::Image());
	Logo->set(imagepath+"about_icon."IMAGE_EXT);
	set_logo(Logo->get_pixbuf());

#ifdef SHOW_EXTRA_INFO

	string extra_info = get_comments() + "\n";

#ifdef _DEBUG

	#ifdef DEVEL_VERSION
		extra_info += strprintf(_("\nDevelopment version:\n%s\n"),DEVEL_VERSION);
	#endif
	
	extra_info += "\n";
	
	extra_info += strprintf(_("Built on %s" /* at %s */ "\n"), __DATE__ /* , __TIME__ */ );

	extra_info += "\n";

	extra_info += strprintf(_("Built with:\n"), ETL_VERSION);
	extra_info += strprintf(_("ETL %s\n"), ETL_VERSION);
	extra_info += strprintf(_("ArtIA API %s\n"), stringify(SYNFIG_VERSION));
	extra_info += strprintf(_("ArtIA library %d\n"), SYNFIG_LIBRARY_VERSION);
	extra_info += strprintf(_("GTK+ %d.%d.%d\n"), GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);

	#ifdef __GNUC__
		extra_info += strprintf(_("GNU G++ %d.%d.%d\n"),__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);
	#endif

	extra_info += "\n";

	extra_info += strprintf(_("Using:\n"), synfig::get_version());
	extra_info += strprintf(_("ArtIA Studio %s\n"), synfig::get_version());
	extra_info += strprintf(_("GTK+ %d.%d.%d"),gtk_major_version,gtk_minor_version,gtk_micro_version);

	extra_info += "\n\nDEBUG BUILD";
#endif

	set_comments(extra_info);

#endif

	// Hide the dialog when you click close
	signal_response().connect(sigc::mem_fun(*this, &About::close));
}

void About::close(int){
	hide();
}

void About::on_link_clicked(Gtk::AboutDialog&, const Glib::ustring &url)
{
	App::open_url(url);
}
